/*平台设备*/

#include <linux/platform_device.h>
#include <linux/init.h>
#include <linux/module.h>
#include "led.h"

/*定义设备卸载函数*/
static void led_release(struct device *dev)
{
	printk("<kernel>call function:%s\n",__FUNCTION__);
}


/*全局变量*/
//定义3个LED引脚
struct rk3399_led_gpio led_gpios[] =
{
	[0] = {.gpio = 55,.desc = "gpio_led2_green"},
	[1] = {.gpio = 56,.desc = "gpio_led2_orange"},
	[2] = {.gpio = 13,.desc = "gpio_led1"},
};

//定义平台数据对象
struct led_platform_data rkled_platform_data =
{
	.pled_gpio = led_gpios,
	.nleds = ARRAY_SIZE(led_gpios),
};

//定义资源对象
static struct resource rk_led_resources[] = 
{
	[0] = {
		.start	= CRU_CLKGATE_CON31,
		.end	= CRU_CLKGATE_CON31 + SIZE_4 - 1,
		.flags	= IORESOURCE_MEM,
	},
	[1] = {
		.start = GRF_GPIO2A_IOMUX,
		.end = GRF_GPIO2A_IOMUX + SIZE_4 - 1,
		.flags = IORESOURCE_MEM,
	},
	[2] = {
		.start	= GPIO2_SWPORTA_DDR,
		.end	= GPIO2_SWPORTA_DDR + SIZE_4 - 1,
		.flags	= IORESOURCE_MEM,
	},
	[3] = {
		.start = GPIO2_SWPORTA_DR,
		.end = GPIO2_SWPORTA_DR + SIZE_4 - 1,
		.flags = IORESOURCE_MEM,
	},
	[4] = {
		.start = 75,
		.end = 75,
		.flags = IORESOURCE_IRQ,
	},	
};

//定义平台设备对象		
static struct platform_device rk_led_device = 
{
	.name						= "rk3399_led",
	.id							= -1,
	.dev 						= {.release = led_release},//父类
	.resource				= rk_led_resources,
	.num_resources	= ARRAY_SIZE(rk_led_resources),
};


/*入口函数*/
static int __init led_init(void)
{
	printk("<kernel>call function:%s\n",__FUNCTION__);	
	return platform_device_register(&rk_led_device);
}

/*出口函数*/
static void __exit led_exit(void)
{
	printk("<kernel>call function:%s\n",__FUNCTION__);
	platform_device_unregister(&rk_led_device);
}

module_init(led_init);
module_exit(led_exit);
MODULE_LICENSE("GPL");


